package cn.wolfcode.luowowo.website.web.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.StrategyDetail;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.comment.domain.StrategyComment;
import cn.wolfcode.luowowo.comment.service.IStrategyCommentService;
import cn.wolfcode.luowowo.search.domain.StrategyTemplate;
import cn.wolfcode.luowowo.search.domain.UserInfoTemplate;
import cn.wolfcode.luowowo.search.service.IStrategySearchService;
import cn.wolfcode.luowowo.search.service.IUserInfoSearchService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class DataController {

    @Reference
    private IStrategyCommentService strategyCommentService;

    @Reference
    private IUserInfoSearchService userInfoSearchService;

    @Reference
    private IStrategySearchService strategySearchService;

    @Reference
    private IStrategyDetailService strategyDetailService;

    @Reference
    private IDestinationService destinationService;

    @RequestMapping("/add")
    @ResponseBody
    public Object addComment(){
        StrategyComment strategyComment = new StrategyComment();
        strategyComment.setUsername("123123");
        strategyCommentService.save(strategyComment);
        return "ok";
    }

    @RequestMapping("/addEs")
    @ResponseBody
    public Object addEs(){
        UserInfoTemplate template = new UserInfoTemplate();
        template.setNickname("xiaolong");
        userInfoSearchService.save(template);
        return "ok";
    }

    @RequestMapping("/dataInit")
    @ResponseBody
    public Object dataInit(){

        //攻略初始化--------------------------

        List<StrategyDetail> details = strategyDetailService.list();

        StrategyTemplate t = null;
        for (StrategyDetail detail : details) {
            t = new StrategyTemplate();
            t.setId(detail.getId());
            t.setTitle(detail.getTitle());
            t.setSubTitle(detail.getSubTitle());
            t.setDestId(detail.getDest().getId());
            t.setDestName(detail.getDest().getName());
            t.setThemeId(detail.getTheme().getId());
            t.setThemeName(detail.getTheme().getName());
            t.setSummary(detail.getSummary());
            t.setCreateTime(detail.getCreateTime());
            t.setViewnum(detail.getViewnum());
            t.setFavornum(detail.getFavornum());
            t.setReplynum(detail.getReplynum());
            t.setThumbsupnum(detail.getThumbsupnum());
            t.setCoverUrl(detail.getCoverUrl());

            //List<String> list = strategyTagService.getTagsBySDetailId(detail.getId());
            //t.setTags(list);

            //获取国家
            Destination dest = destinationService.getCountry(detail.getDest().getId());
            t.setCountryId(dest.getId());
            t.setCountryName(dest.getName());

            //获取省份
            dest = destinationService.getProvince(detail.getDest().getId());
            if(dest != null){
                t.setProvinceId(dest.getId());
                t.setProvinceName(dest.getName());
            }

            strategySearchService.save(t);

        }
        //end--------------------------


        return "ok";
    }

}
